package com.scm.biz.action;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.scm.biz.bean.BusinessFile;
import com.scm.biz.service.BusinessFileService;
import com.scm.core.bean.exp.UfdmException;
import com.scm.core.bean.resp.RespBean;
import com.scm.utils.UploadAndDownUtil;
@Controller
@RequestMapping("/businessfile")
public class BusinessFileAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7059183937137675836L;
	@Resource
	BusinessFileService businessFileService;
	@RequestMapping("/selectlist")
	@ResponseBody
	public RespBean<List<BusinessFile>> selectList(Long businessId,String category){
		RespBean<List<BusinessFile>> respBean = new RespBean<>();
		respBean.setBody(businessFileService.selectListByBusinessId(businessId,category));
		return respBean;
	}
	@RequestMapping("/insert")
	@ResponseBody
	public RespBean<List<BusinessFile>> insert(Long businessId,String category,MultipartFile file) throws UfdmException{
		RespBean<List<BusinessFile>> respBean = new RespBean<>();
		System.out.println(category+"");
		businessFileService.insert(file,businessId,category,null);
		return respBean;
	}
	@RequestMapping("/delete")
	@ResponseBody
	public RespBean<List<BusinessFile>> deleteById(Long id){
		RespBean<List<BusinessFile>> respBean = new RespBean<>();
		businessFileService.removeById(id);
		return respBean;
	}
	/**
	 * 客户附件下载
	 * @param businessFileId 附件ID
	 * @param res
	 * @throws UfdmException 
	 */
	@RequestMapping("downFile")
	public void downFile(Long businessFileId,HttpServletRequest req,HttpServletResponse res) throws UfdmException{
		BusinessFile file=businessFileService.selectByKey(businessFileId);
		UploadAndDownUtil.downFile(file.getOriginName(), file.getBusinessFile(), req, res);
	}
}
